﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

using Styx;
using Styx.Helpers;
using Styx.Plugins.PluginClass;
using Styx.WoWInternals;
using System.Drawing;

namespace Answer
{
    class Worker
    {
        private string m_partner;
        private string m_message;
        private bool m_ignore;
        private int m_delay;


        public Worker(string partner, string message, bool ignore, int delay)
        {
            this.m_partner = partner;
            this.m_message = message;
            this.m_ignore = ignore;
            this.m_delay = delay;

        }

        private void IgnorePlayer(string PlayerName)
        {
            Logging.Write(Color.Green, "[AutoAnswer] - Ignore Player " + PlayerName);
            Lua.DoString("AddOrDelIgnore(\"" + PlayerName + "\")");
        }

        private void SendToWoWChat(string MessageType, string szMessage, string szReciever)
        {

            switch (MessageType)
            {
                case "WHISPER_MESSAGE":
                    Logging.Write(Color.Green, "[AutoAnswer] - Send WHISPER_MESSAGE");
                    Lua.DoString("SendChatMessage(\"" + szMessage + "\", \"WHISPER\", nil, \"" + szReciever + "\");");
                    break;
                case "SAY_MESSAGE":
                    Logging.Write(Color.Green, "[AutoAnswer] - Send SAY_MESSAGE");
                    Lua.DoString("SendChatMessage(\"" + szMessage + "\", \"SAY\", nil, nil);");
                    break;
                case "GUILD_MESSAGE":
                    Logging.Write(Color.Green, "[AutoAnswer] - Send GUILD_MESSAGE");
                    Lua.DoString("SendChatMessage(\"" + szMessage + "\", \"GUILD\", nil, nil);");
                    break;
                case "YELL_MESSAGE":
                    Logging.Write(Color.Green, "[AutoAnswer] - Send YELL_MESSAGE");
                    Lua.DoString("SendChatMessage(\"" + szMessage + "\", \"YELL\", nil, nil);");
                    break;
                default:
                    break;

            }
        }
        public void Execute()
        {
            Thread.Sleep(m_delay);
            SendToWoWChat("WHISPER_MESSAGE", this.m_message, this.m_partner);
            
            if(m_ignore)
                IgnorePlayer(this.m_partner);
        }


        
    }
}
